package es.shinra.app;


import es.shinra.app.BBDD.Object.DAO.DBAction;
import es.shinra.app.BBDD.Object.DAO.DBManager;
import es.shinra.app.BBDD.Object.DAO.iDBAction;
import es.shinra.app.BBDD.Object.DAO.iDBActionResult;
import es.shinra.app.BBDD.Object.iContent;
//import java.sql.Connection;
//import java.sql.Statement;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

import java.sql.ResultSet;
import java.sql.DriverManager;
import java.util.List;
import java.util.Vector;
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;



/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )throws Exception{


        
    

       // BBDD eXist





        System.out.println( "Hello World! " );
        List <String >ActionId = new Vector();
        iDBAction aDBAction = new DBAction();
        ActionId.add("eXist");
        aDBAction.setActionId(ActionId);
        aDBAction.setParameters(ActionId);
        DBManager aManager = DBManager.getInstance();
        iDBActionResult aDBActionResult=null;
        iContent aContent;
        if(aManager==null){
            System.out.println("El Manager es NULL");
        }else{
            aDBActionResult = aManager.execute(aDBAction);
            if(aDBActionResult.isOk()){
                aContent = aDBActionResult.getResult();
                System.out.println("Resultado final "+aContent.getContent());
            }else{
                System.out.println(aDBActionResult.getErrorMsg());
            }
        }
        ActionId.clear();
        ActionId.add("sql");
        aDBActionResult = aManager.execute(aDBAction);
            if(aDBActionResult.isOk()){
                aContent = aDBActionResult.getResult();
                System.out.println("Resultado final "+aContent.getContent());
            }else{
                System.out.println(aDBActionResult.getErrorMsg());
            }

            /*
        //===============JDBC
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        //cd /usr/local/mysql
        //sudo echo
        // sudo ./bin/mysqld_safe &
        Connection conexion = (Connection) DriverManager.getConnection("jdbc:mysql://localhost/test");//", "", "");
        Statement st = (Statement) conexion.createStatement();
        st.executeUpdate("DROP TABLE contacto");
        st.executeUpdate("CREATE TABLE contacto (id INT AUTO_INCREMENT, PRIMARY KEY(id), nombre VARCHAR(20), apellidos VARCHAR(20), telefono VARCHAR(20))");
        //st.executeUpdate("DROP TABLE contacto");
        String nombres[]={"Juan","Pedro","Antonio"};
        String apellidos[]={"Gomez","Lopez","Alvarez"};
        String telefonos[]={"123","456","789"};

        for (int i=0;i<nombres.length;i++)
           st.executeUpdate("INSERT INTO contacto (nombre, apellidos, telefono) VALUES ('"+nombres[i]+"','"+apellidos[i]+"','"+telefonos[i]+"' )");
        ResultSet rs = st.executeQuery("SELECT * FROM contacto");
        while (rs.next()){
           System.out.println("nombre="+rs.getObject("nombre")+
              ", apellidos="+rs.getObject("apellidos")+
              ", telefono="+rs.getObject("telefono"));
        }
        rs.close();
        conexion.close();*/

    }
}
